package com.login.action;

import java.util.List;

import com.login.service.PersonService;
import com.login.vo.Person;
import com.opensymphony.xwork2.ActionSupport;

public class PersonAction extends ActionSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private PersonService personService;
	
	private Person person;
	
	private Person condition;
	
	private List<Person> list;
	
	private Integer id;

	public String query() {
		// TODO Auto-generated method stub
		try {
			list = personService.queryPersonList(condition);
			return SUCCESS;
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return ERROR;
	}
	
	public String toAdd() {
		return "toAdd";
	}
	
	public String add() {
		try {
			personService.addPerson(person);
			
			return "add";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return ERROR;
	}
	
	public String delete() {
		try {
			personService.deletePerson(id);
			return "delete";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return ERROR;
	}
	
	public String toUpdate() {
		try {
			person = personService.queryPerson(id);
			return "toUpdate";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return ERROR;
	}
	
	public String update() {
		try {
			personService.updatePerson(person);
			return "update";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return ERROR;
	}
	
	public PersonService getPersonService() {
		return personService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public List<Person> getList() {
		return list;
	}

	public void setList(List<Person> list) {
		this.list = list;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Person getCondition() {
		return condition;
	}

	public void setCondition(Person condition) {
		this.condition = condition;
	}

}
